const express = require('express')
const router = express.Router();
module.exports = router

const db = require('../db')
const { formatData } = require('../utils')

// GET /api/goods/list   获取商品列表
router.get('/list', async (req, res) => {

    // 数据库操作
    let sql = `select * from goodslist`
    const data = await db.query(sql)
    res.send(formatData({data}))
})

// GET /api/goods/some   获取部分商品
router.get('/some', async (req, res) => {
    const {index=1,qty=7} = req.query
    // 数据库操作
    let sql = `select * from goodslist order by id limit 0,${qty*index}`
    const data = await db.query(sql)
    res.send(formatData({data}))
})

//GET /api/goods/student
router.get('/student', async (req,res)=>{
    const {page=1} = req.query
    const sql = `select * from clients limit ${(page*1-1)*9},9;`
        const data = await db.query(sql)
        res.send(formatData({data}))
})

// GET /api/goods/home
router.get('/home', async (req,res)=>{
    const sql = `select * from home ;`
        const data = await db.query(sql)
        res.send(formatData({data}))
})